/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DataPenyewaanMobilPanel.java
 *
 * Created on Nov 18, 2011, 5:44:42 PM
 */
package DataMobil;

import DBKoneksi.*;
import DataPenyewa.*;
import Login.*;
import java.awt.event.*;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.*;
import javax.swing.*;

/**
 *
 * @author Piyo
 */
public class DataPenyewaanMobilPanel extends javax.swing.JPanel {

    /** Creates new form DataPenyewaanMobilPanel */
    public DataPenyewaanMobilPanel() {
        initComponents();
        GregorianCalendar gc = new GregorianCalendar();
        tanggalChooserSewa.setEnabled(false);

        tanggalChooserSewa.setDate(gc.getTime());
        tanggalChooserKembali.setDate(gc.getTime());
        buatnomor();
        NAMAOPTF.setText(Login.getLogin1().getUsername());
        ActionListener taskPerformer = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                String nol_jam = "";
                String nol_menit = "";
                String nol_detik = "";
                // Membuat Date
                Date dt = new Date();
                // Mengambil nilaj JAM, MENIT, dan DETIK Sekarang
                int nilai_jam = dt.getHours();
                int nilai_menit = dt.getMinutes();
                int nilai_detik = dt.getSeconds();
                // Jika nilai JAM lebih kecil dari 10 (hanya 1 digit)
                if (nilai_jam <= 9) {
                    // Tambahkan "0" didepannya
                    nol_jam = "0";
                }
                // Jika nilai MENIT lebih kecil dari 10 (hanya 1 digit)
                if (nilai_menit <= 9) {
                    // Tambahkan "0" didepannya
                    nol_menit = "0";
                }
                // Jika nilai DETIK lebih kecil dari 10 (hanya 1 digit)
                if (nilai_detik <= 9) {
                    // Tambahkan "0" didepannya
                    nol_detik = "0";
                }
                // Membuat String JAM, MENIT, DETIK
                String jam = nol_jam + Integer.toString(nilai_jam);
                String menit = nol_menit + Integer.toString(nilai_menit);
                String detik = nol_detik + Integer.toString(nilai_detik);
                // Menampilkan pada Layar
                JAMTF.setText("  " + jam + " : " + menit + " : " + detik + "  ");
            }
        };
        // Timer
        new Timer(1000, taskPerformer).start();
    }

    private void buatnomor() {
        try {
            Statement statement = TestConection.getConnection().createStatement();
            String sql = "select max(to_number(notransaksisewa)) as no from datapenyewaan";
            ResultSet rs = statement.executeQuery(sql);

            if (rs.next()) {
                int no_t = Integer.parseInt(rs.getString("no")) + 1;
                String nomor_t = String.valueOf(no_t);

                int panjang_karakter = nomor_t.length();

                while (panjang_karakter <= 2) {
                    nomor_t = "0" + nomor_t;
                    panjang_karakter++;
                }
                NOTRANTF.setText(String.valueOf(nomor_t));
            } else {
                NOTRANTF.setText("001");
            }
            rs.close();
        } catch (Exception e) {
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField6 = new javax.swing.JTextField();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        judulLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        Notranstxt = new javax.swing.JLabel();
        nama = new javax.swing.JLabel();
        tanggalSewaLabel = new javax.swing.JLabel();
        jam = new javax.swing.JLabel();
        JAMTF = new javax.swing.JTextField();
        NOTRANTF = new javax.swing.JTextField();
        NAMAOPTF = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        IDPenyewatxt = new javax.swing.JLabel();
        NamaPenyewatxt = new javax.swing.JLabel();
        alamatxt = new javax.swing.JLabel();
        telepontxt = new javax.swing.JLabel();
        TlpnTF = new javax.swing.JTextField();
        IDTF = new javax.swing.JTextField();
        NamaTF = new javax.swing.JTextField();
        AlamatTF = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();
        idMobilLabel = new javax.swing.JLabel();
        namaMobilLabel = new javax.swing.JLabel();
        warnaMobilLabel = new javax.swing.JLabel();
        merkMobilLabel = new javax.swing.JLabel();
        idMobilTF = new javax.swing.JTextField();
        namaMobilTF = new javax.swing.JTextField();
        warnaMobilTF = new javax.swing.JTextField();
        merkMobilTF = new javax.swing.JTextField();
        jSeparator4 = new javax.swing.JSeparator();
        hargaSewaLabel = new javax.swing.JLabel();
        jenisLayananLabel = new javax.swing.JLabel();
        lamaSewaLabel = new javax.swing.JLabel();
        jenisPenyewaLabel = new javax.swing.JLabel();
        hargaSewaTF = new javax.swing.JTextField();
        lamaSewaField = new javax.swing.JTextField();
        submitButton = new javax.swing.JButton();
        totalLabel = new javax.swing.JLabel();
        totalField = new javax.swing.JTextField();
        tanggalChooserSewa = new com.toedter.calendar.JDateChooser();
        layananBox = new javax.swing.JComboBox();
        jenisPenyewaBox = new javax.swing.JComboBox();
        tanggalKembaliLabel = new javax.swing.JLabel();
        tanggalChooserKembali = new com.toedter.calendar.JDateChooser();
        backgroundLabel = new javax.swing.JLabel();

        jTextField6.setText("jTextField6");

        jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));

        judulLabel.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 14));
        judulLabel.setForeground(new java.awt.Color(255, 255, 255));
        judulLabel.setText("Form Penyewaan Mobil");
        judulLabel.setBounds(220, 10, 190, 20);
        jDesktopPane1.add(judulLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(0, 50, 660, 10);
        jDesktopPane1.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Notranstxt.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        Notranstxt.setForeground(new java.awt.Color(255, 255, 255));
        Notranstxt.setText("No Transaksi");
        Notranstxt.setBounds(10, 60, 90, 30);
        jDesktopPane1.add(Notranstxt, javax.swing.JLayeredPane.DEFAULT_LAYER);

        nama.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        nama.setForeground(new java.awt.Color(255, 255, 255));
        nama.setText("Nama Operator");
        nama.setBounds(10, 100, 100, 30);
        jDesktopPane1.add(nama, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tanggalSewaLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        tanggalSewaLabel.setForeground(new java.awt.Color(255, 255, 255));
        tanggalSewaLabel.setText("Tanggal Sewa");
        tanggalSewaLabel.setBounds(330, 100, 90, 30);
        jDesktopPane1.add(tanggalSewaLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jam.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        jam.setForeground(new java.awt.Color(255, 255, 255));
        jam.setText("Jam ");
        jam.setBounds(330, 60, 140, 30);
        jDesktopPane1.add(jam, javax.swing.JLayeredPane.DEFAULT_LAYER);

        JAMTF.setEditable(false);
        JAMTF.setBounds(440, 60, 150, 30);
        jDesktopPane1.add(JAMTF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NOTRANTF.setEditable(false);
        NOTRANTF.setBounds(110, 60, 140, 30);
        jDesktopPane1.add(NOTRANTF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NAMAOPTF.setEditable(false);
        NAMAOPTF.setBounds(110, 100, 140, 30);
        jDesktopPane1.add(NAMAOPTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator2.setBounds(0, 140, 650, 20);
        jDesktopPane1.add(jSeparator2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IDPenyewatxt.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        IDPenyewatxt.setForeground(new java.awt.Color(255, 255, 255));
        IDPenyewatxt.setText("ID Penyewa");
        IDPenyewatxt.setBounds(10, 150, 100, 30);
        jDesktopPane1.add(IDPenyewatxt, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NamaPenyewatxt.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        NamaPenyewatxt.setForeground(new java.awt.Color(255, 255, 255));
        NamaPenyewatxt.setText("Nama Penyewa");
        NamaPenyewatxt.setBounds(10, 190, 90, 30);
        jDesktopPane1.add(NamaPenyewatxt, javax.swing.JLayeredPane.DEFAULT_LAYER);

        alamatxt.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        alamatxt.setForeground(new java.awt.Color(255, 255, 255));
        alamatxt.setText("Alamat");
        alamatxt.setBounds(320, 150, 120, 30);
        jDesktopPane1.add(alamatxt, javax.swing.JLayeredPane.DEFAULT_LAYER);

        telepontxt.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        telepontxt.setForeground(new java.awt.Color(255, 255, 255));
        telepontxt.setText("NO Telepon");
        telepontxt.setBounds(320, 190, 120, 30);
        jDesktopPane1.add(telepontxt, javax.swing.JLayeredPane.DEFAULT_LAYER);
        TlpnTF.setBounds(440, 190, 150, 30);
        jDesktopPane1.add(TlpnTF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IDTF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                IDTFKeyReleased(evt);
            }
        });
        IDTF.setBounds(110, 150, 140, 30);
        jDesktopPane1.add(IDTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        NamaTF.setBounds(110, 190, 140, 30);
        jDesktopPane1.add(NamaTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        AlamatTF.setBounds(440, 150, 150, 30);
        jDesktopPane1.add(AlamatTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator3.setBounds(0, 230, 660, 20);
        jDesktopPane1.add(jSeparator3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        idMobilLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        idMobilLabel.setForeground(new java.awt.Color(255, 255, 255));
        idMobilLabel.setText("ID Mobil");
        idMobilLabel.setBounds(10, 240, 90, 30);
        jDesktopPane1.add(idMobilLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        namaMobilLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        namaMobilLabel.setForeground(new java.awt.Color(255, 255, 255));
        namaMobilLabel.setText("Nama Mobil");
        namaMobilLabel.setBounds(10, 280, 100, 30);
        jDesktopPane1.add(namaMobilLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        warnaMobilLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        warnaMobilLabel.setForeground(new java.awt.Color(255, 255, 255));
        warnaMobilLabel.setText("Warna Mobil");
        warnaMobilLabel.setBounds(320, 240, 130, 30);
        jDesktopPane1.add(warnaMobilLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        merkMobilLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        merkMobilLabel.setForeground(new java.awt.Color(255, 255, 255));
        merkMobilLabel.setText("Merk Mobil");
        merkMobilLabel.setBounds(320, 280, 120, 30);
        jDesktopPane1.add(merkMobilLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        idMobilTF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                idMobilTFKeyReleased(evt);
            }
        });
        idMobilTF.setBounds(110, 240, 140, 30);
        jDesktopPane1.add(idMobilTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        namaMobilTF.setBounds(110, 280, 140, 30);
        jDesktopPane1.add(namaMobilTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        warnaMobilTF.setBounds(440, 240, 150, 30);
        jDesktopPane1.add(warnaMobilTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        merkMobilTF.setBounds(440, 280, 150, 30);
        jDesktopPane1.add(merkMobilTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator4.setBounds(0, 320, 660, 10);
        jDesktopPane1.add(jSeparator4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        hargaSewaLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        hargaSewaLabel.setForeground(new java.awt.Color(255, 255, 255));
        hargaSewaLabel.setText("Harga Sewa");
        hargaSewaLabel.setBounds(10, 330, 100, 30);
        jDesktopPane1.add(hargaSewaLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jenisLayananLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        jenisLayananLabel.setForeground(new java.awt.Color(255, 255, 255));
        jenisLayananLabel.setText("Jenis Layanan");
        jenisLayananLabel.setBounds(10, 370, 90, 20);
        jDesktopPane1.add(jenisLayananLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lamaSewaLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        lamaSewaLabel.setForeground(new java.awt.Color(255, 255, 255));
        lamaSewaLabel.setText("Lama Sewa");
        lamaSewaLabel.setBounds(10, 450, 90, 30);
        jDesktopPane1.add(lamaSewaLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jenisPenyewaLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        jenisPenyewaLabel.setForeground(new java.awt.Color(255, 255, 255));
        jenisPenyewaLabel.setText("Jenis Penyewa");
        jenisPenyewaLabel.setBounds(320, 340, 90, 20);
        jDesktopPane1.add(jenisPenyewaLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        hargaSewaTF.setBounds(110, 330, 140, 30);
        jDesktopPane1.add(hargaSewaTF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lamaSewaField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                lamaSewaFieldKeyPressed(evt);
            }
        });
        lamaSewaField.setBounds(110, 450, 140, 30);
        jDesktopPane1.add(lamaSewaField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        submitButton.setText("Submit");
        submitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitButtonActionPerformed(evt);
            }
        });
        submitButton.setBounds(490, 440, 90, -1);
        jDesktopPane1.add(submitButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        totalLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        totalLabel.setForeground(new java.awt.Color(255, 255, 255));
        totalLabel.setText("Total");
        totalLabel.setBounds(320, 380, 120, 30);
        jDesktopPane1.add(totalLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        totalField.setBounds(440, 380, 150, 30);
        jDesktopPane1.add(totalField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tanggalChooserSewa.setDateFormatString("dd-MM-yyyy");
        tanggalChooserSewa.setBounds(440, 100, 150, 30);
        jDesktopPane1.add(tanggalChooserSewa, javax.swing.JLayeredPane.DEFAULT_LAYER);

        layananBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sopir", "Tanpa Sopir", " " }));
        layananBox.setBounds(110, 370, 140, -1);
        jDesktopPane1.add(layananBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jenisPenyewaBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Instansi", "Pribadi", " " }));
        jenisPenyewaBox.setBounds(440, 340, 150, -1);
        jDesktopPane1.add(jenisPenyewaBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tanggalKembaliLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 11));
        tanggalKembaliLabel.setForeground(new java.awt.Color(255, 255, 255));
        tanggalKembaliLabel.setText("Tanggal Kembali");
        tanggalKembaliLabel.setBounds(10, 420, 90, 20);
        jDesktopPane1.add(tanggalKembaliLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tanggalChooserKembali.setDateFormatString("dd-MM-yyyy");
        tanggalChooserKembali.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tanggalChooserKembaliPropertyChange(evt);
            }
        });
        tanggalChooserKembali.setBounds(110, 410, 140, 30);
        jDesktopPane1.add(tanggalChooserKembali, javax.swing.JLayeredPane.DEFAULT_LAYER);

        backgroundLabel.setForeground(new java.awt.Color(0, 51, 153));
        backgroundLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DataMobil/hucomm5jv7-iam-blue-wallpaper.jpg"))); // NOI18N
        backgroundLabel.setBounds(0, 0, 670, 530);
        jDesktopPane1.add(backgroundLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 645, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 514, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitButtonActionPerformed
// TODO add your handling code here:
    try {
        String tampil = "dd-MM-yyyy";
        SimpleDateFormat format = new SimpleDateFormat(tampil);
        String tanggalSewa = String.valueOf(format.format(tanggalChooserSewa.getDate()));
        String tanggalKembali = String.valueOf(format.format(tanggalChooserKembali.getDate()));

        int hargaSewa = Integer.parseInt(hargaSewaTF.getText());
        int lamaSewa = Integer.parseInt(lamaSewaField.getText());
        int total = Integer.parseInt(totalField.getText());

        String sql = "insert into DATAPENYEWAAN values ('" + NOTRANTF.getText()
                + "','" + NAMAOPTF.getText()
                + "','" + tanggalSewa
                + "','" + IDTF.getText()
                + "','" + NamaTF.getText()
                + "','" + AlamatTF.getText()
                + "','" + TlpnTF.getText()
                + "','" + idMobilTF.getText()
                + "','" + namaMobilTF.getText()
                + "','" + warnaMobilTF.getText()
                + "','" + merkMobilTF.getText()
                + "','" + hargaSewa
                + "','" + layananBox.getSelectedItem().toString()
                + "','" + jenisPenyewaBox.getSelectedItem().toString()
                + "','" + tanggalKembali
                + "','" + lamaSewa
                + "','" + total + "') ";

        Statement statement = TestConection.getConnection().createStatement();
        statement.executeUpdate(sql);
        JOptionPane.showMessageDialog(null, "Data berhasil di simpan");

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Proses penyimpanan gagal/koneksi gagal");
        System.out.println(e.getMessage());
    }
}//GEN-LAST:event_submitButtonActionPerformed

private void IDTFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_IDTFKeyReleased
    try {
        DataPenyewa p = new DataPenyewa();
        String id_Penyewa = IDTF.getText();
        p.setID_penyewa(id_Penyewa);

        Intermobil interM = new Intermobil();
        interM.getByIdPenyewa(p);

        String namaP = p.getNama_penyewa();
        String alamatP = p.getAlamat();
        String teleponP = p.getNo_telepon();

        NamaTF.setText(namaP);
        AlamatTF.setText(alamatP);
        TlpnTF.setText(teleponP);

    } catch (SQLException ex) {
        Logger.getLogger(DataPenyewaanMobilPanel.class.getName()).log(Level.SEVERE, null, ex);
    }

}//GEN-LAST:event_IDTFKeyReleased

private void idMobilTFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_idMobilTFKeyReleased
    try {
        // TODO add your handling code here:
        DataMobil m = new DataMobil();
        String id_Mobil = idMobilTF.getText();
        m.setId_mobil(id_Mobil);

        Intermobil interM = new Intermobil();
        interM.getByIdMobil(m);

        String namaM = m.getNama_mobil();
        String warnaM = m.getWarna();
        String merkM = m.getMerk_Mobil();
        int hargaSewaM = m.getHarga_sewa();

        namaMobilTF.setText(namaM);
        warnaMobilTF.setText(warnaM);
        merkMobilTF.setText(merkM);
        hargaSewaTF.setText(String.valueOf(hargaSewaM));
    } catch (SQLException ex) {
        Logger.getLogger(DataPenyewaanMobilPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_idMobilTFKeyReleased

private void lamaSewaFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lamaSewaFieldKeyPressed
// TODO add your handling code here:

    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        int harga = Integer.parseInt(hargaSewaTF.getText());
        int lamaSewa = Integer.parseInt(lamaSewaField.getText());
        String jenisLayanan = layananBox.getSelectedItem().toString();
        String jenisPenyewa = jenisPenyewaBox.getSelectedItem().toString();
        if (jenisLayanan.equals("Sopir")) {
            double total = harga * lamaSewa + 100000;
            totalField.setText(String.valueOf(total));
        } else if (jenisLayanan.equals("Tanpa Sopir") && jenisPenyewa.equals("Pribadi")) {
            double total = harga * lamaSewa;
            totalField.setText(String.valueOf(total));
        } else {
            double total = harga * lamaSewa + 50000;
            totalField.setText(String.valueOf(total));
        }
    }

}//GEN-LAST:event_lamaSewaFieldKeyPressed

    private int kabisat(int a) {
        if (((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0)) {
            return 1;
        }
        return 0;
    }

private void tanggalChooserKembaliPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tanggalChooserKembaliPropertyChange
    // TODO add your handling code here:
    String tgl = "dd";
    String bln = "MM";
    String thn = "yyyy";
    SimpleDateFormat format = new SimpleDateFormat(tgl);
    SimpleDateFormat format2 = new SimpleDateFormat(bln);
    SimpleDateFormat format3 = new SimpleDateFormat(thn);

    String tanggalSewa = String.valueOf(format.format(tanggalChooserSewa.getDate()));
    String tanggalKembali = String.valueOf(format.format(tanggalChooserKembali.getDate()));

    String bulanSewa = String.valueOf(format2.format(tanggalChooserSewa.getDate()));
    String bulanKembali = String.valueOf(format2.format(tanggalChooserKembali.getDate()));

    String tahunSewa = String.valueOf(format3.format(tanggalChooserSewa.getDate()));
    String tahunKembali = String.valueOf(format3.format(tanggalChooserKembali.getDate()));

    int tglSewa = Integer.parseInt(tanggalSewa);
    int tglKembali = Integer.parseInt(tanggalKembali);

    int blnSewa = Integer.parseInt(bulanSewa);
    int blnKembali = Integer.parseInt(bulanKembali);

    int thnSewa = Integer.parseInt(tahunSewa);
    int thnSewaK = kabisat(thnSewa);
    int thnKembali = Integer.parseInt(tahunKembali);

    if (thnSewa == thnKembali) { //tahun sewa dan tahun kembali sama
        if (blnSewa == blnKembali) { //bulan sewa dan bulan kembali sama
            if (tglSewa == tglKembali) { //tanggal sewa dan tanggal kembali sama
                lamaSewaField.setText("");
            } else if (tglKembali > tglSewa) { //tanggal kembali lebih dari tanggal sewa
                lamaSewaField.setText(String.valueOf(tglKembali - tglSewa));
            } else { //tanggal kembali kurang dari tanggal sewa
                JOptionPane.showMessageDialog(null, "Tanggal kembali harus lebih dari tanggal sewa!");
                lamaSewaField.setText("");
            }

        } else if (blnKembali - blnSewa == 1) { //selisih bulan kembali dan sewa = 1
            if (tglSewa == tglKembali) { //lama sewa 1 bulan
                JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
                lamaSewaField.setText("");
            } else if (tglKembali > tglSewa) { //lama sewa lebih dari 1 bulan
                JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
                lamaSewaField.setText("");
            } else if (blnSewa == 1 || blnSewa == 3 || blnSewa == 5 || blnSewa == 7 || blnSewa == 8 || blnSewa == 10 || blnSewa == 12) { //3
                //tanggal sewa berada di bulan 1,3,5,7,8,10,12 dan tanggal kembali di bulan selain bulan tersebut
                int lama = 31 + tglKembali - tglSewa;
                if (lama > 21) { //lama sewa kurang dari 1 bulan tetapi lebih dari 3 minggu
                    JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
                    lamaSewaField.setText("");
                } else { //lama sewa <= 21
                    lamaSewaField.setText(String.valueOf(lama));
                }


            } else if (blnSewa == 4 || blnSewa == 6 || blnSewa == 9 || blnSewa == 11) {
                //tanggal sewa berada di bulan 4,6,9,11 dan tanggal kembali di bulan selain bulan tersebut
                int lama = 30 + tglKembali - tglSewa;
                if (lama > 21) { //lama sewa kurang dari 1 bulan tetapi lebih dari 3 minggu
                    JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
                    lamaSewaField.setText("");
                } else { //lama sewa <= 21
                    lamaSewaField.setText(String.valueOf(lama));
                }

            } else if (blnSewa == 2 && thnSewaK == 1) {
                //tanggal sewa berada di bulan 2 (tahun kabisat) dan tanggal kembali di bulan 3
                int lama = 29 + tglKembali - tglSewa;
                if (lama > 21) { //lama sewa kurang dari 1 bulan tetapi lebih dari 3 minggu
                    JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
                    lamaSewaField.setText("");
                } else { //lama sewa <= 21
                    lamaSewaField.setText(String.valueOf(lama));
                }
            } else { //tanggal sewa berada di bulan 2 (bukan tahun kabisat) dan tanggal kembali di bulan 3
                int lama = 28 + tglKembali - tglSewa;
                if (lama > 21) { //lama sewa kurang dari 1 bulan tetapi lebih dari 3 minggu
                    JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
                    lamaSewaField.setText("");
                } else { //lama sewa <= 21
                    lamaSewaField.setText(String.valueOf(lama));
                }
            }

        } else if (blnKembali - blnSewa > 1) { //lama sewa lebih dari 3 minggu
            JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
            lamaSewaField.setText("");

        } else { //bulan kembali kurang dari bulan sewa
            JOptionPane.showMessageDialog(null, "Tanggal kembali harus lebih dari tanggal sewa!");
            lamaSewaField.setText("");
        }


    } else if (thnKembali > thnSewa && blnSewa == 12 && blnKembali == 1) {
        //tanggal sewa di bulan 12 dan tanggal kembali di bulan 1
        int lama = 31 + tglKembali - tglSewa;
        if (lama > 21) { //lama sewa kurang dari 1 bulan tetapi lebih dari 3 minggu
            JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
            lamaSewaField.setText("");
        } else { //lama sewa <=21
            lamaSewaField.setText(String.valueOf(lama));
        }

    } else if (thnKembali < thnSewa) { //tahun kembali kurang dari tahun sewa
        JOptionPane.showMessageDialog(null, "Tanggal kembali harus lebih dari tanggal sewa!");
        lamaSewaField.setText("");

    } else { //lama sewa lebih dari 3 minggu
        JOptionPane.showMessageDialog(null, "Lama sewa maksimal 3 minggu!");
        lamaSewaField.setText("");
    }

}//GEN-LAST:event_tanggalChooserKembaliPropertyChange
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AlamatTF;
    private javax.swing.JLabel IDPenyewatxt;
    private javax.swing.JTextField IDTF;
    private javax.swing.JTextField JAMTF;
    private javax.swing.JTextField NAMAOPTF;
    private javax.swing.JTextField NOTRANTF;
    private javax.swing.JLabel NamaPenyewatxt;
    private javax.swing.JTextField NamaTF;
    private javax.swing.JLabel Notranstxt;
    private javax.swing.JTextField TlpnTF;
    private javax.swing.JLabel alamatxt;
    private javax.swing.JLabel backgroundLabel;
    private javax.swing.JLabel hargaSewaLabel;
    private javax.swing.JTextField hargaSewaTF;
    private javax.swing.JLabel idMobilLabel;
    private javax.swing.JTextField idMobilTF;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JLabel jam;
    private javax.swing.JLabel jenisLayananLabel;
    private javax.swing.JComboBox jenisPenyewaBox;
    private javax.swing.JLabel jenisPenyewaLabel;
    private javax.swing.JLabel judulLabel;
    private javax.swing.JTextField lamaSewaField;
    private javax.swing.JLabel lamaSewaLabel;
    private javax.swing.JComboBox layananBox;
    private javax.swing.JLabel merkMobilLabel;
    private javax.swing.JTextField merkMobilTF;
    private javax.swing.JLabel nama;
    private javax.swing.JLabel namaMobilLabel;
    private javax.swing.JTextField namaMobilTF;
    private javax.swing.JButton submitButton;
    private com.toedter.calendar.JDateChooser tanggalChooserKembali;
    private com.toedter.calendar.JDateChooser tanggalChooserSewa;
    private javax.swing.JLabel tanggalKembaliLabel;
    private javax.swing.JLabel tanggalSewaLabel;
    private javax.swing.JLabel telepontxt;
    private javax.swing.JTextField totalField;
    private javax.swing.JLabel totalLabel;
    private javax.swing.JLabel warnaMobilLabel;
    private javax.swing.JTextField warnaMobilTF;
    // End of variables declaration//GEN-END:variables
}
